//
//  ZZUserInfoCell.m
//  QQplayground
//
//  Created by zhangxy on 2018/6/7.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "ZZUserInfoCell.h"
#import "ZZHomeTopMenu.h"

@implementation ZZUserInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _imgAvatar.layer.cornerRadius = _imgAvatar.frame.size.height/2;
    _imgAvatar.layer.masksToBounds = YES;
    
    [self setLayerButton:_btnZan];
    [_btnZan.titleLabel setFont:FontSeventeen];
    [_btnZanCool setImage:[UIImage imageNamed:@"个人页点赞"] forState:0];
    
    [_imgSex setImage:[UIImage imageNamed:@"sex_boy"]];
    
    [_labName setFont:[UIFont boldSystemFontOfSize:21]];
    [_labName setTextColor:UIColorFromRGB(TextWhiteColor)];
    
    [_labLevel setFont:ListElevenFont];
    _labLevel.layer.cornerRadius = 4.0f;
    [_labLevel setTextAlignment:NSTextAlignmentCenter];
    _labLevel.layer.masksToBounds = YES;
    _labLevel.layer.borderColor = UIColorFromRGB(BorderLineColor).CGColor;
    [_labLevel setTextColor:UIColorFromRGB(TextSizeOneColor)];
    _labLevel.layer.borderWidth = 1.0f;
    
    [_btnOpenVip setImage:[UIImage imageNamed:@"开通会员"] forState:0];
    [_btnOpenVip setBackgroundColor:UIColor.clearColor];
    
    [_labDesc setFont:ListElevenFont];
    [_labLabels setFont:ListElevenFont];
    [_labDesc setTextColor:UIColorFromRGB(TextWhiteColor)];
    [_labLabels setTextColor:UIColorFromRGB(TextWhiteColor)];
    
    [self setLayerButton:_btnDS];
    [self setLayerButton:_btnAge];
    [self setLayerButton:_btnCity];
    [self setLayerButton:_btnQQ];
    
    [_labNumber setTextColor:UIColorFromRGB(TextWhiteColor)];
    [_labNumber setFont:FontThirteen];
    
    [_btnZanYellow setImage:[UIImage imageNamed:@"金币"] forState:0];
    [_btnZanYellow setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [_btnZanYellow.titleLabel setFont:FontThirteen];
    [_btnZanYellow setBackgroundColor:UIColor.clearColor];
    
    
    [_btnZanCool setImage:[UIImage imageNamed:@"钻石"] forState:0];
    [_btnZanCool setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [_btnZanCool.titleLabel setFont:FontThirteen];
    [_btnZanCool setBackgroundColor:UIColor.clearColor];
    
    
    [_btnTap1 setBackgroundColor:UIColor.clearColor];
    [_btnTap1 setBackgroundImage:[UIImage imageNamed:@"素材"] forState:0];
    [_btnTap1 setTitleColor:UIColorFromRGB(BgTitleColor) forState:0];
    [_btnTap1.titleLabel setFont:ListElevenFont];
    [_btnTap1 setTitle:@"素材" forState:0];
    
    [_btnTap2 setBackgroundColor:UIColor.clearColor];
    [_btnTap2 setBackgroundImage:[UIImage imageNamed:@"帖子"] forState:0];
    [_btnTap2 setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [_btnTap2.titleLabel setFont:ListElevenFont];
    [_btnTap2 setTitle:@"帖子" forState:0];
    [_btnTap2 addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [_btnTap3 setBackgroundColor:UIColorFromRGB(BgTitleColor)];
    [_btnTap3 setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [_btnTap3.titleLabel setFont:ListElevenFont];
    [_btnTap3 setTitle:@"秘密" forState:0];
    [_btnTap3 addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //    CGRect f = _btnTap3.frame;
    //    f.origin.x = f.origin.x - f.size.width;
    //    [_btnTap2 setFrame:f];
    //    f.origin.x = f.origin.x - f.size.width;
    //    [_btnTap1 setFrame:f];
}

-(void)tapClick:(UIButton *) btn{
    if([btn isEqual:_btnTap3]){
        if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
            [self.delegate onHeaderCellItemClick:ZZHeaderTypeMimi obj:nil];
        }
    }
    if([btn isEqual:_btnTap2]){
        if(self.delegate && [self.delegate respondsToSelector:@selector(onHeaderCellItemClick:obj:)]){
            [self.delegate onHeaderCellItemClick:ZZHeaderTypeTiezi obj:nil];
        }
    }
}

-(void)dataToView:(User *) user{
    
    [_viewMenus setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
    CGRect f = _viewMenus.frame;
    f.size.width = ScreenWidth;
    _viewMenus.frame = f;
    [ZZViewUtils cutViewRound:_viewMenus radius:10 byRoundingCorners:UIRectCornerTopLeft];
    
    
    [_imgAvatar sd_setImageWithURL:[NSURL URLWithString:user.user_avatar] placeholderImage:[UIImage imageNamed:@"default_image"]];
    [_labName setText:user.user_name];
    [_labLevel setText:[NSString stringWithFormat:@"Lv %zd",user.group_now_grade]];
    [_btnZan setTitle:user.user_diamond forState:0];
    if(user.user_gender == 1){
        [_imgSex setImage:[UIImage imageNamed:@"sex_boy"]];
    }else{
        [_imgSex setImage:[UIImage imageNamed:@"sex_girl"]];
    }
    [_labDesc setText:user.user_sign];
    [_labLabels setText:user.group_name];
    [_btnDS setTitle:user.user_emotion forState:0];
    
    user.birth_day = @"3";
    user.birth_month=@"2";
    user.birth_year=@"1988";
    if(convertToString(user.birth_year).length > 0 && convertToString(user.birth_month).length > 0 && convertToString(user.birth_day).length > 0){
        if([user.birth_day intValue] < 10){
            user.birth_day = [NSString stringWithFormat:@"0%@",user.birth_day];
        }
        if([user.birth_month intValue] < 10){
            user.birth_month = [NSString stringWithFormat:@"0%@",user.birth_month];
        }
        NSString *birday = [NSString stringWithFormat:@"%@-%@-%@",user.birth_year,user.birth_month,user.birth_day];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        // this is imporant - we set our input date format to match our input string
        // if format doesn't match you'll get nil from your string, so be careful
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSDate *birthday = [dateFormatter dateFromString:birday];
        [_btnAge setTitle:[NSString stringWithFormat:@"%@岁",dateToAge(birthday)] forState:0];
    }else{
        [_btnAge setTitle:@"" forState:0];
    }
    [_btnCity setTitle:user.user_constellation forState:0];
    [_btnQQ setTitle:[NSString stringWithFormat:@"QQ%@",convertToString(user.user_qq)] forState:0];
    
    [_labNumber setText:[NSString stringWithFormat:@"%@ 关注    %@ 粉丝    %@ 访客    %@ 留言", convertToString(user.count_follow),convertToString(user.count_fans),convertToString(user.count_visit),convertToString(user.count_wall)]];
    
    
    [_btnZanYellow setTitle:user.user_gold forState:0];
    [_btnZanCool setTitle:user.user_diamond forState:0];
    
    [_btnOpenVip setTitle:@"" forState:0];
    if([user.user_blood boolValue]){
        [_btnOpenVip setImage:[UIImage imageNamed:@"开通会员"] forState:0];
    }
    else{
        [_btnOpenVip setImage:[UIImage imageNamed:@"vip"] forState:0];
    }
    
    
    UIImageView *imgLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 2, ScreenWidth, 2)];
    [imgLine setBackgroundColor:UIColorFromRGB(BgSystemColor)];
    [self addSubview:imgLine];
}

-(void)setList_now:(NSMutableArray *)list_now{
    if(list_now != nil && list_now.count > 0){
        NSMutableArray *arrList = [[NSMutableArray alloc] init];
        for (NavTypeEntity *item in list_now) {
            [arrList addObject:item.nav_name];
        }
        ZZHomeTopMenu *menu = [[ZZHomeTopMenu alloc] initWithFrame:CGRectMake(10, 0, ScreenWidth-20,44) array:arrList textColor:UIColorFromRGB(Text6Color) checkColor:UIColorFromRGB(BgTitleColor) result:^(NSInteger tag, NSString *title) {
            if(self.delegate && [self.delegate respondsToSelector:@selector(onMenuClick:obj:)]){
                [self.delegate onMenuClick:tag obj:nil];
            }
        }];
        [_viewMenus.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [_viewMenus addSubview:menu];
    }
}

-(void)setLayerButton:(UIButton *) btn{
    [btn setBackgroundColor:UIColorFromRGBAlpha(TextWhiteColor, 0.3)];
    btn.layer.cornerRadius = btn.frame.size.height / 2;
    btn.layer.masksToBounds = YES;
    [btn.titleLabel setFont:ListElevenFont];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    [btn setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [btn setTitleColor:UIColorFromRGB(TextWhiteColor) forState:UIControlStateSelected];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
